import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        /*String str=in.nextLine();
        str=str.toUpperCase();
        StringBuilder sb=new StringBuilder();
        sb.append(str.charAt(0));
        for (int i = 1; i < str.length(); i++) {
            if(str.charAt(i-1)==' '&&str.charAt(i)!=' '){
                sb.append(str.charAt(i));
            }
        }
        System.out.println(sb.toString());*/
        /*int n = in.nextInt();
        int x = in.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        int dest = 0,cur = 0,min = Integer.MAX_VALUE,temp = 0,resultIndex1 = 0,resultIndex2 = 0;
        while (cur < arr.length) {
            temp += arr[cur++];
            while (temp >= x){
                if (min > cur - dest + 1) {
                    min = cur - dest + 1;
                    resultIndex1 = dest;
                    resultIndex2 = cur;
                }
                temp -= arr[dest++];
            }

        }
        System.out.println(resultIndex1 + 1 + " " + resultIndex2);*/
        /*int n = in.nextInt();
        long k = in.nextLong();
        long[] arr = new long[n];
        long sum = 0;
        PriorityQueue<Long> heap = new PriorityQueue<>(Comparator.reverseOrder());
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextLong();
            if (arr[i] % 2 == 0) {
                heap.add(arr[i]);
            }
            else{
                sum+=arr[i];
            }
        }
        while (k-- > 0 && !heap.isEmpty()) {
            long num=heap.poll()/2;
            if(num%2==0){
                heap.add(num);
            }
            else {
                sum+=num;
            }
        }
        int size = heap.size();
        while(!heap.isEmpty()){
            sum+=heap.poll();
        }
        System.out.println(sum);*/
        /*while (k-->0){
            Arrays.sort(arr);
            int i=n-1;
            for (; i >= 0; i--) {
                if(arr[i]%2==0){
                  arr[i]/=2;
                  break;
                }
            }
            if(i==-1){
                break;
            }
        }
        long sum=0;
        for (long a:arr){
            sum+=a;
        }
        System.out.println(sum);*/
        long num= in.nextLong();
        long ret=Long.MAX_VALUE;
        List<Long> fb=new ArrayList<>();
        fb.add((long)0);
        ret=Math.min(ret,Math.abs(num-fb.get(0)));
        fb.add((long)1);
        ret=Math.min(ret,Math.abs(num-fb.get(1)));
        for (int i = 2; i < num; i++) {
            fb.add(fb.get(i-1)+fb.get(i-2));
            ret=Math.min(ret,Math.abs(num-fb.get(i)));
        }
        System.out.println(ret);
        int n=in.nextInt();
        int[][] arr=new int[n][n];
        for(int i=0;i<n;i++){
            arr[i][0]=1;
            arr[i][i]=1;
        }
        for(int i=2;i<n;i++){
            for(int j=1;j<i;j++){
                arr[i][j]=arr[i-1][j]+arr[i-1][j-1];
            }
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<=i;j++){
                System.out.printf("%5d",arr[i][j]);
            }
            System.out.println();
        }
    }
    public boolean exist (String[] board, String word) {
        int n=board.length,m=board[0].length();
        char[] arr1=word.toCharArray();
        int k=0;
        char[][] boards=new char[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                boards[i][j]=board[i].charAt(j);
            }
        }
        boolean[][] visits=new boolean[n][m];
        return backtrack(boards,arr1,visits,k,0,0);
        /*for (int i = 1; i < n+1; i++) {
            for (int j = 1; j < m+1; j++) {
               if(dfs(boards,arr1,k,i,j)){
                   return true;
               }
            }
        }
        return false;*/

    }
    public boolean backtrack(char[][] boards,char[] arr1,boolean[][]visits,int k,int i,int j){
        if(k==arr1.length){
            return false;
        }
        if(i<0||i>boards.length-1||j<0||j>boards[0].length-1||visits[i][j]||boards[i][j]!=arr1[k]){
            return false;
        }
        visits[i][j]=true;
        boolean found=backtrack(boards,arr1,visits,k+1,i+1,j)||backtrack(boards,arr1,visits,k+1,i-1,j)
                ||backtrack(boards,arr1,visits,k+1,i,j+1)||backtrack(boards,arr1,visits,k+1,i,j-1);
        visits[i][j]=false;
        return found;
    }
    public boolean dfs(char[][] boards,char[] arr1,int k,int i,int j){
        while (boards[i][j]==arr1[k]){
            k++;
            if(k==arr1.length){
                return true;
            }
            if(boards[i-1][j]==arr1[k]){
                i=i-1;
            } else if (boards[i+1][j]==arr1[k]) {
                i=i+1;
            } else if (boards[i][j-1]==arr1[k]) {
                j=j-1;
            } else if (boards[i][j+1]==arr1[k]) {
                j=j+1;
            }
            else {
                k=0;
            }
        }
        return false;
    }
}